// pages/jishuguanli/jishuguanli.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    jishu: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    let tableName = "jishu"

    // 应用查询对象
    let Product = new wx.BaaS.TableObject(tableName)

    // 不设置查询条件
    Product.find().then(res => {
      // success
      console.log(res.data.objects)
      var items = []
      var i = 0
      var A = res.data.objects
      var s = res.data.objects[0].leixing
      while (i < A.length) {
        var item = {
          leixing: s,
          bg: [],
          tab: [],
          bgc: [],
          tab2: [],
          ids: [],
          contents: []
        }
        console.log(i)
        for (var j = i; j < A.length; j++) {
          var a = Math.floor(Math.random() * 5)
          var c = Math.floor(Math.random() * 5)
          var b = Math.floor(Math.random() * 4)
          if (A[i].leixing == item.leixing) {
            item.contents.push(res.data.objects[i])
            item.bg.push(app.globalData.color[a])
            item.tab.push(app.globalData.tab[b])
            item.bgc.push(app.globalData.color[c])
            item.tab2.push(app.globalData.tab[b])
            item.ids.push(j)
            A.splice(i, 1)
            i++;

          }
        }
        console.log(A.length)
        i = 0;
        if (A.length != 0) {
          s = A[0].leixing;
        }
        if (item.contents.length != 0) {
          items.push(item)
        }
      }
      this.setData({
        item: items
      })
      app.globalData.jishuliebiao = items
    }, err => {
      // err
    })

  },
  /**
   * 跳转到列表
   * @param {*} e 
   */
  jishuliebiao(e) {
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: '../jishuguanli/jishu/jishu?id=' + e.currentTarget.dataset.id,
    })
  }
})